package org.nimi317.web_gis.controller;

import cn.hutool.core.util.ObjectUtil;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.nimi317.web_gis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
 * @author thunderobot
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private RedisService redisService;

    @GetMapping
    public void demo(HttpServletResponse response) {
        String string = UUID.randomUUID().toString();
        Set<Object> set = redisService.getCacheSet("sign");
        if(ObjectUtil.isEmpty(set)) {
            set = new HashSet<>();
        }
        set.add(string);
        redisService.setCacheSet("sign", set);
        response.addCookie(new Cookie("sign",string));
    }
}
